package com.example.demo.mvc;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.entity.Mark;
import com.example.demo.service.MarkService;

@Controller
@RequestMapping("/getMarks")
public class MarkAction {
	@Autowired
	private MarkService markServiceimpl;
	private List<Mark> markList1;
	private int eb;
	//@Autowired
	//private FileUploaderAndDownloaderutil fileUploaderAndDownloaderutil;
	//private String fileName;
    private Mark mark1;
    
	@RequestMapping("/insertMark")
	public ModelAndView insertMark(@ModelAttribute("mark") Mark mark){
		ModelAndView modelAndView= new ModelAndView();
		eb= markServiceimpl.addMark(mark);
		if(eb==1){
			modelAndView.setViewName("selectMark");
			return modelAndView;
		}
		modelAndView.setViewName("error");
		modelAndView.addObject("erormes","抱歉,添加失败");
		return modelAndView;
	}
	
	
	@RequestMapping("/deleteMark")
	public ModelAndView deleteMark(@RequestParam("kid") Integer kid){
		ModelAndView modelAndView=  new ModelAndView();
		eb=markServiceimpl.delMark(kid);
		if(eb==1){
			modelAndView.setViewName("selectMark");
			return modelAndView;
		}
		modelAndView.setViewName("error");
		modelAndView.addObject("errormes","抱歉,删除失败");
		return modelAndView;
	}
	
	@RequestMapping("/updateStudent")
	public ModelAndView updateMark(@ModelAttribute("mark") Mark mark){
		ModelAndView modelAndView= new ModelAndView();
		eb= markServiceimpl.updateMark(mark);
		if(eb==1){
			modelAndView.setViewName("selectMark");
			return modelAndView;
		}
		modelAndView.setViewName("error");
		modelAndView.addObject("erormes","抱歉,修改失败");
		return modelAndView;
	}
	
	@RequestMapping("/selectMark")
	public ModelAndView selectMark(){
		markList1=new ArrayList<Mark>();
		markList1= markServiceimpl.selectMark();
		ModelAndView modelAndView= new ModelAndView();
		modelAndView.setViewName("selectMark");
		modelAndView.addObject("markList1",markList1);
		return modelAndView;
	}
	
	@RequestMapping("/selectOneMark/{kid}")
	public ModelAndView selectOneMark(@PathVariable("kid") Integer kid){
		mark1=new Mark();
		mark1= markServiceimpl.selectOneMark(kid);
		ModelAndView modelAndView= new ModelAndView();
		modelAndView.setViewName("selectOneMark");
		modelAndView.addObject("mark",mark1);
		return modelAndView;
	}
	
	@RequestMapping("/insertMark1")
	public String insertMark2(Mark mark){
		return "/insertMark1";
	}
}
